package com.bole.controller;

import com.bole.config.ElasticSearchConfig;
import com.bole.data.Result;
import com.bole.dto.car.Page;
import com.bole.service.EsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;




@RequestMapping("search")
@Api(value = "搜索管理api")
@RestController

public class EsController {

    @Autowired
    private EsService esService;



    @GetMapping("searchInfo")
    @ApiOperation(value = "查询车辆信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "searchName",value = "searchName",required = true,dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageNum",value = "pageNum",required = true,dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize",value = "pageSize",required = true,dataTypeClass = Integer.class),
    })
    public Page listSearchByName(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, @RequestParam("searchName") String searchName) {
        Page page = esService.listSearchByName(pageNum, pageSize, searchName);
        return page;
    }


    @PostMapping("selectCarSeriesId")
    @ResponseBody
    @ApiOperation(value = "根据车系查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "pageNum", required = true, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "carSeriesId", value = "carSeriesId", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "detailsId", value = "detailsId", required = true, dataTypeClass = String.class),
    })
    public Page selectCarSeriesId(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize,
                                  @RequestParam("carSeriesId") Long carSeriesId,
                                  @RequestParam("detailsId") String detailsId) {
        Page page = esService.selectCarSeriesId(pageNum, pageSize, carSeriesId,detailsId);
        return page;
    }

    @PostMapping("updateStatus")
    @ResponseBody
    @ApiOperation(value = "修改状态")
    @ApiImplicitParam(name = "carId", value = "carId", required = true, dataTypeClass = Long.class)
    public void updateStatus(@RequestParam("carId") Long carId) {
         esService.updateStatus(carId);

    }

}
